import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'

import arrow from '@assets/images/arrow-right.png'

import './index.scss'

class XHead extends Component {
  constructor(props) {
    super(props)
  }

  // 跳转页面
  handleLink () {
    if (this.props.url) {
      Taro.navigateTo(this.props.url)
    }
  }

  render() { 
    return (
      <View className='x-head' onClick={this.handleLink.bind(this)}>
        <Text>{this.props.title}</Text>
        <Image src={this.props.src} className='x-head__img' />
      </View>
    )
  }
}

XHead.defaultProps = {
  src: arrow,
  title: '',
  url: ''
}

export default XHead
